package nowcoder.day_48.day7;

import java.util.Scanner;

/*
斐波那契
 */
public class Num1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int n = 0;
        while (fib(n) < N){
            n++;
        }
        System.out.println(Math.min(fib(n) - N, N - fib(n - 1)));


    }
    public static int fib(int n){
        if (n == 0)return 0;
        if (n == 1)return 1;
        return fib(n - 1) + fib(n - 2);
    }
}
